<?php
require_once('../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/local/itusurveyplugin/lib.php');
require_once($CFG->dirroot . "/local/itusurveyplugin/forms.php");

//Require authentication and authorization
require_login($SITE);
require_capability('local/itusurveyplugin:manageitusurvey', context_system::instance());

//prepare moodle_url
global $DB;
$path = $CFG->wwwroot.'/local/itusurveyplugin/itusurvey/clone_survey.php';

/* Chuan bi trang web can hien thi */	
$url = new moodle_url($path);
$PAGE->set_url($url);
$PAGE->set_title('Clone ITU Survey');
$PAGE->set_heading('Clone ITU Survey');
$PAGE->set_pagelayout('standard');

navigation_node::override_active_url(new moodle_url($path, array('param'=>'value')));

echo $OUTPUT->header();
//Include functions
$mylib = new survey_management();
//New form instance
$mform = new form_clone_survey(null, null);

//cancel action
if ($mform->is_cancelled()) {

echo 'hủy thao tác';

}
//submit action 
else if ($fromform = $mform->get_data()) 
{	
    $fromform = $mform->get_data();
    //user who clone the survey
    $user = $_POST["user_id"];
    //cloned survey
    $survey = $_POST["selected_survey"];
    
    $new_survey = $mylib->clone_survey($survey,$user);
    echo "<script>redirectTo('edit_survey.php?id=".$new_survey."')</script>";
}
//Invalid Received Data or First Load
else{
    //Set default data (if any)
    //$mform->set_data($toform);
    //Used for first load   
}

$mform->display();
echo $OUTPUT->footer();

?>